/**
 * @Description
 * @author 20155870 杨润增
 * @create 2018-06-09 21:42
 **/
package com.campus_information_portal.service.impl;

import com.campus_information_portal.dao.PunishDao;
import com.campus_information_portal.entity.Punish;
import com.campus_information_portal.entity.StuPunish;
import com.campus_information_portal.service.PunishService;
import com.campus_information_portal.util.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className PunishImpl
 * @Description
 * @author
 * @create 2018-06-09 21:42
 **/
@Service
public class PunishImpl implements PunishService{
    @Autowired
    private PunishDao punishDao;

    @Override
    public Message queryAllPunish() {
        List<StuPunish> list=punishDao.queryAllPunish();
        if (list!=null){
            return Message.success().add("list",list);
        }else
            return Message.fail().add("0701","查询结果为空");
    }

    @Override
    public Message queryPunishByStuNum(Integer stuNum) {
        if (stuNum!=null&&stuNum>=0){
            List<StuPunish> list=punishDao.queryAllPunish();
            if (list!=null){
                return Message.success().add("list",list);
            }else
                return Message.fail().add("0702","查询结果为空");
        }else
            return Message.fail().add("0703","学号错误");

    }

    @Override
    public Message addPunish(Punish punish) {
        try {
            System.out.println(punish);
            punishDao.addPunish(punish);
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return  Message.fail().add("0704","增加失败");

    }

    @Override
    public Message deletePunish(Integer punishId) {
        try {
            punishDao.deletePunish(punishId);
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return Message.fail().add("0705","删除失败");
    }

    @Override
    public Message editPunish(Integer punishId, String punishType) {
        try {
            punishDao.updatePunish(punishId,punishType);
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return Message.fail().add("0705","更新失败");
    }

    @Override
    public Message editPunishStatus(Integer punishId, Integer status) {
        try {
            punishDao.updatePunishStatus(punishId,status);
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return Message.fail().add("0706","更新失败");
    }
}
